#ifndef QLIGHT_H
#define QLIGHT_H

#include <QObject>
#include <QWidget>
#include <QPaintEvent>
#include <QPainter>
#include <QTimer>

/**
 * @brief The QLight class
 * @author zxx
 * @details
 * 使用painter绘制的状态灯
 */
class QLight : public QWidget
{
    Q_OBJECT
public:
    explicit QLight(QWidget *parent = nullptr);

    void Open();
    void Close();
    void Default();
    void Error();
    /**
     * @brief Blink
     * @details
     * 闪烁分为，紧急事件和连接事件
     * 连接时   为蓝灯
     * 紧急时   为红灯
     */
    void Blink(bool);
    void StopBlink();
private:
    void initUI();
protected:
    void paintEvent(QPaintEvent *) override;

private:
    void setState(bool state);
    void toggle();
    void setOnColor(QColor onColor);
    void setOffColor(QColor offColor);
    void setOnPattern(Qt::BrushStyle onPattern);
    void setOffPattern(Qt::BrushStyle offPattern);
    void setLedSize(int size);

public slots:
    void switchLedIndicator();

private:
    bool lit;   // 记录当前灯的状态
    bool r_init;// 如果是多态  true:当前是初始化
    bool blink;
    QColor ledOnColor;
    QColor ledDefault;
    QColor ledOffColor;
    Qt::BrushStyle ledOnPattern;
    Qt::BrushStyle ledOffPattern;
    int ledSize;
    QTimer *timer;
};


#endif // QLIGHT_H
